package com.yaorange.teaching.mapper;

import java.util.List;
import java.util.Map;

import com.yaorange.teaching.bo.ScoreTrendBo;
import com.yaorange.teaching.domain.YaExamDetail;
import com.yaorange.teaching.domain.YaExamRecord;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 学生成绩记录Mapper接口
 *
 * @author ruoyi
 * @date 2024-11-13
 */
public interface YaExamRecordMapper
{
    /**
     * 查询学生成绩记录
     *
     * @param id 学生成绩记录主键
     * @return 学生成绩记录
     */
    public YaExamRecord selectYaExamRecordById(Long id);

    /**
     * 查询学生成绩记录列表
     *
     * @param yaExamRecord 学生成绩记录
     * @return 学生成绩记录集合
     */
    public List<YaExamRecord> selectYaExamRecordList(YaExamRecord yaExamRecord);

    /**
     * 新增学生成绩记录
     *
     * @param yaExamRecord 学生成绩记录
     * @return 结果
     */
    public int insertYaExamRecord(YaExamRecord yaExamRecord);

    /**
     * 修改学生成绩记录
     *
     * @param yaExamRecord 学生成绩记录
     * @return 结果
     */
    public int updateYaExamRecord(YaExamRecord yaExamRecord);

    /**
     * 删除学生成绩记录
     *
     * @param id 学生成绩记录主键
     * @return 结果
     */
    public int deleteYaExamRecordById(Long id);

    /**
     * 批量删除学生成绩记录
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteYaExamRecordByIds(Long[] ids);

    List<YaExamDetail> selectYaExamDetailList(@Param("classesId") Long classesId);

    @Select("select max(week) last_week from ya_exam_record where classes_id = #{classesId} and stage = #{stage}")
    Integer selectLastWeek(@Param("classesId")Long classesId, @Param("stage")Long stage);

    @Select("SELECT\n" +
            "\tconcat(record.stage,'阶段', record.`week`,\"周\") title, \n" +
            "\tavg((IFNULL(detail.computer_score, 0)+IFNULL(detail.written_score, 0))/2)  AS average_score\n" +
            "FROM\n" +
            "\tya_exam_detail AS detail\n" +
            "\tINNER JOIN\n" +
            "\tya_exam_record AS record\n" +
            "\tON \n" +
            "\t\tdetail.exam_record_id = record.id\n" +
            "WHERE\n" +
            "\tdetail.user_id = #{studentId} group by title ")
    List<Map<String, Object>> selectScoreTrend(@Param("studentId")Long studentId);



    List<Map<String, Object>> selectScoreDistribution(@Param("classesId")Long classesId);
}
